﻿Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.Http

Module GumballMachineTestDrive
    Sub Main(ByVal args() As String)
        Dim count As Integer = 0

        If args.Length < 2 Then
            Console.WriteLine("GumballMachine <name> <inventory>")
            Return
        End If

        Try
            count = Convert.ToInt32(args(1))
        Catch ex As Exception
            Console.WriteLine(ex.StackTrace)
            Return
        End Try

        Dim gumballMachine As New GumballMachine(args(0), count)
        Dim monitor As New GumballMonitor(gumballMachine)

        'Marshall our monitor to remote
        Dim channel As New HttpChannel(8989)
        Dim monitorRef As ObjRef = RemotingServices.Marshal(monitor, "GumballMonitor.rem")
        Console.WriteLine(monitorRef.URI)

        Console.WriteLine(gumballMachine.ToString)
        Console.ReadLine()

        gumballMachine.InsertQuarter()
        gumballMachine.TurnCrank()
        gumballMachine.InsertQuarter()
        gumballMachine.TurnCrank()

        Console.WriteLine(gumballMachine.ToString)
        Console.ReadLine()

        gumballMachine.InsertQuarter()
        gumballMachine.TurnCrank()
        gumballMachine.InsertQuarter()
        gumballMachine.TurnCrank()

        Console.WriteLine(gumballMachine.ToString)
        Console.ReadLine()

        gumballMachine.InsertQuarter()
        gumballMachine.TurnCrank()
        gumballMachine.InsertQuarter()
        gumballMachine.TurnCrank()

        Console.WriteLine(gumballMachine.ToString)
        Console.ReadLine()

        gumballMachine.InsertQuarter()
        gumballMachine.TurnCrank()
        gumballMachine.InsertQuarter()
        gumballMachine.TurnCrank()

        Console.WriteLine(gumballMachine.ToString)
        Console.ReadLine()

        gumballMachine.InsertQuarter()
        gumballMachine.TurnCrank()
        gumballMachine.InsertQuarter()
        gumballMachine.TurnCrank()

        Console.WriteLine(gumballMachine.ToString)
        Console.ReadLine()

        Console.WriteLine(monitor.GetReport())
    End Sub
End Module
